<!DOCTYPE HTML>
<html>
<head>
    <title>添加商城弹出Logo</title>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <script src="/scripts/jquery.min.js"></script>
    <link rel="stylesheet" href="/stylesheets/formdata.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">

    <script src="/scripts/miniui/miniui.js"></script>
    <script src="/qiniuJs/liveFormdata.js"></script>
    <script src="/qiniuJs/livePicFormdata.js"></script>

</head>
<body>
<div class="container" style="display: inline-block;width: 95%;">
    <form id="testformPic" method="post" enctype="multipart/form-data">
        <input name="key" id="keyPic" type="hidden" value="">
        <input name="token" type="hidden" value="<%= uptokenPic %>">
        <input id="userfilePic" name="file" style="display: none" accept="image/*" type="file"/>
        <input name="accept" type="hidden"/>
    </form>
    <!-- add file -->
    <label for="userfilePic" >
        <span></span>
        <em>添加LOGO</em>
    </label>

    <!-- upload info -->
    <div class="selected-file-pic"></div>
    <div class="progress-pic"></div>
    <div class="uploaded-result-pic"></div>
</div>
<div id="form1" style="padding-left: 30px">
    <span style="width:100px;display:inline-block;">商品所属商城：</span>
    <input id="shopGoodsType" name="shopGoodsType" class="mini-combobox" required="true" style="width:150px;" data="shopGoodsTypeData" value="0"/>
    <span style="width:40px;display:inline-block;margin-left: 10px;">商品：</span>
    <input id="btnEdit1" class="mini-buttonedit" onbuttonclick="onButtonEdit" name="a" textName="b" style="width:150px;"/>
    <br/><br/>
    <!--<span style="width:100px;display:inline-block;">点击跳转URL：</span>-->
    <!--<input id="goodsUrl" name="goodsUrl" class="mini-textbox" required="true"  type="text" style="width:360px;" />-->
    <!--<br/><br/>-->
    <input id="coverPic" required="true" class="mini-textbox" style="display: none"/>
    <div style="margin: 0 auto;text-align: center">
        <a class="mini-button " iconCls="icon-ok" onclick="add()">确定</a>
        <a class="mini-button" iconCls="icon-cancel" onclick="onCancel">取消</a>
    </div>
</div>
</body>
<script>
  var domain = "<%- domain %>";
  let shopGoodsTypeData = [{id:0,text:'普通商城'},{id:1,text:'积分商城'}]
  function add() {
    var form = new mini.Form("#form1");
    form.validate();
    if (form.isValid() == false) {
      alert("请正确填写数据")
      return
    };
    let data = {}
    var coverPic = mini.get("coverPic").getValue();
    if (coverPic){
      data.logo = 'http://tribemedia.aladada.com/'+coverPic
    } else {
      alert('请添加LOGO!')
      return
    }
    var shopGoodsType = mini.get("shopGoodsType").getValue();
    data.shopGoodsType = shopGoodsType
    if (shopGoodsType == 0){
      var shopGoodsOId = mini.get("btnEdit1").getValue();
      data.shopGoodsOId = shopGoodsOId
      data.goodsUrl = 'http://health.aladada.com/goods/infoNew?id='+shopGoodsOId+'&type=2'
    } else if (shopGoodsType == 1){
      var scoreShopGoodsOId = mini.get("btnEdit1").getValue();
      data.scoreShopGoodsOId = scoreShopGoodsOId
      data.goodsUrl = 'http://health.aladada.com/goods/scoreGoodsInfo?id='+scoreShopGoodsOId+'&type=2'
    } else {
      alert('未获得商品ID！')
    }
    $.ajax({
      type: "POST",
      url: "/getdata/addShopPopUpLogo",
      data: data,
      success: function (result) {
        if (result){
          CloseWindow("save");
        }
      },
      fail: function (error) {
        console.log(error)
      }
    })
  }

  //    关闭窗口
  function CloseWindow(action) {
    if (action == "close" && form.isChanged()) {
      if (confirm("数据被修改了，是否先保存？")) {
        return false;
      }
    }
    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
    else window.close();
  }

  function onOk(e) {
    SaveData();
  }

  function onCancel(e) {
    CloseWindow("cancel");
  }

  function onButtonEdit(e) {
    var btnEdit = this;
    let type = mini.get("shopGoodsType").getValue()
    console.log(type)
    if (type == 0){
      mini.open({
        url: "/editor/shopGoodsChoice",
        title: "商品列表",
        width: 1100,
        height: 450,
        ondestroy: function (action) {
          if (action == "ok") {
            var iframe = this.getIFrameEl();
            var data = iframe.contentWindow.GetData();
            data = mini.clone(data);    //必须
            if (data) {
              btnEdit.setText(data.text);
              btnEdit.setValue(data.id);
            }
          }else {
            btnEdit.setText("");
          }

        }
      });
    } else if (type == 1){
      mini.open({
        url: "/editor/scoreShopGoodsChoice",
        title: "积分商城商品列表",
        width: 1100,
        height: 450,
        ondestroy: function (action) {
          if (action == "ok") {
            var iframe = this.getIFrameEl();
            var data = iframe.contentWindow.GetData();
            data = mini.clone(data);    //必须
            if (data) {
              btnEdit.setText(data.text);
              btnEdit.setValue(data.id);
            }
          }else {
            btnEdit.setText("");
          }

        }
      });
    } else {
      alert('商品所属商城类型错误！')
    }


  }

</script>
</html>